package com.ngkj.zmfptback.sys.initData.servicie.read.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ngkj.zmfptback.sys.initData.bean.SysDict;
import com.ngkj.zmfptback.sys.initData.mapper.read.DictMapper;
import com.ngkj.zmfptback.sys.initData.servicie.read.DictService;
import com.ngkj.zmfptback.sys.initData.util.DictUtil;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author ChenHN
 * @since 2021/10/27 creation
 **/
@Service
public class DictServiceImpl extends ServiceImpl<DictMapper,SysDict> implements DictService {

    @Resource
    private DictMapper dictMapper;


    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    @Override
    public Map<String, List<SysDict>> getAllSysDict(String status) {
        List<SysDict> allSysDict = dictMapper.getAllSysDict(status);
        Map<String, List<SysDict>> dictsData = DictUtil.getDictsData(allSysDict, "dict_type");
        return dictsData;
    }

    @Override
    public List<SysDict> getSelectDicts(String dictType) {
        String cacheName = "appCodeCache."+dictType;
        List<SysDict> sysDicts = (List<SysDict>) redisTemplate.opsForValue().get(cacheName);
        return sysDicts;
    }

    @Override
    public IPage<SysDict> getDictPage(Page<SysDict> page, SysDict sysDict) {
        return dictMapper.getDictPage(page,sysDict);
    }


}
